<template>
  <div class="layout-padding-auto layout-padding-view" style="border: none; padding: 0">
    <div class="system-user-search mb24">
      <el-input v-model="state.tableData.param.search" placeholder="请输入数据名称" style="max-width: 180px">
      </el-input>
      <el-button type="primary" class="ml10">
        <el-icon>
          <ele-Search />
        </el-icon>
        查询
      </el-button>
      <el-button type="success" class="ml10" @click="onOpenAddRole('add')">
        <el-icon>
          <ele-FolderAdd />
        </el-icon>
        新增
      </el-button>
    </div>
    <el-table :data="state.tableData.data" v-loading="state.tableData.loading">
      <el-table-column prop="id" label="站点编号" width="140" />
      <el-table-column prop="province" label="省份" width="140"></el-table-column>
      <el-table-column prop="name" label="站名" width="180"></el-table-column>
      <el-table-column prop="type" label="站类" width="140"></el-table-column>
      <el-table-column prop="jd" label="经度" width="140"></el-table-column>
      <el-table-column prop="wd" label="纬度" width="140"> </el-table-column>
      <el-table-column prop="gcchb" label="观测场海拔高度（米）" width="270"></el-table-column>
      <el-table-column prop="qycgqhb" label="气压传感器海拔高度（米）" width="290"></el-table-column>
      <el-table-column label="操作" fixed="right" width="140">
        <template #default="scope">
          <el-button
            :disabled="scope.row.roleName === '超级管理员'"
            text
            type="primary"
            @click="onOpenEditRole('edit', scope.row)"
          >
            修改
          </el-button>
          <el-button :disabled="scope.row.roleName === '超级管理员'" text type="primary" @click="onRowDel(scope.row)">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="flex" style="justify-content: end">
      <el-pagination
        @size-change="onHandleSizeChange"
        @current-change="onHandleCurrentChange"
        class="mt15"
        :pager-count="5"
        :page-sizes="[10, 20, 30]"
        v-model:current-page="state.tableData.param.pageNum"
        background
        v-model:page-size="state.tableData.param.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="state.tableData.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script setup lang="ts" name="pageTable">
import { reactive, onMounted } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';

// 定义变量内容
const state = reactive<any>({
  tableData: {
    data: [],
    total: 0,
    loading: false,
    param: {
      search: '',
      pageNum: 1,
      pageSize: 10,
    },
  },
});
// 初始化表格数据
const getTableData = () => {
  state.tableData.loading = true;
  const data = [];
  for (let i = 0; i < 20; i++) {
    data.push({
      id: 3234 + i,
      province: '黑龙江',
      name: '北极村站点',
      type: '基准站',
      jd: '行政区划',
      wd: `2023`,
      gcchb: '52.33',
      qycgqhb: '188.2',
    });
  }
  state.tableData.data = data;
  state.tableData.total = state.tableData.data.length;
  setTimeout(() => {
    state.tableData.loading = false;
  }, 500);
};
// 打开新增弹窗
const onOpenAddRole = (type: string) => {
  // roleDialogRef.value.openDialog(type);
  console.log(type);
};
// 打开修改弹窗
const onOpenEditRole = (type: string, _row: Object) => {
  // roleDialogRef.value.openDialog(type, row);
  console.log(type);
};
// 删除
const onRowDel = (row: RowRoleType) => {
  ElMessageBox.confirm(`此操作将永久删除名称：“${row.roleName}”，是否继续?`, '提示', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  })
    .then(() => {
      getTableData();
      ElMessage.success('删除成功');
    })
    .catch(() => {});
};
// 分页改变
const onHandleSizeChange = (val: number) => {
  state.tableData.param.pageSize = val;
  getTableData();
};
// 分页改变
const onHandleCurrentChange = (val: number) => {
  state.tableData.param.pageNum = val;
  getTableData();
};
// 页面加载时
onMounted(() => {
  getTableData();
});
</script>

<style scoped lang="scss"></style>
